//
//  UPOrderCategoryCell.m
//  LoveFreshBee
//
//  Created by wyzc on 16/6/12.
//  Copyright © 2016年 叶落知秋. All rights reserved.
//

#import "UPOrderCategoryCell.h"
#import "UPOrderCategoryModel.h"
@interface UPOrderCategoryCell ()
@property (weak, nonatomic) IBOutlet UIView *leftLine;
@property (weak, nonatomic) IBOutlet UILabel *categoryNameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *rightImageView;

@end

@implementation UPOrderCategoryCell

-(void)setModel:(UPOrderCategoryModel *)model
{
    _model=model;
    self.categoryNameLabel.text=model.name;
    if (model.flag.length) {
        //下载图片
        dispatch_queue_t
        queue=dispatch_queue_create("abc", NULL);
        dispatch_async(queue, ^{
            NSURL *url=[NSURL URLWithString:model.flag];
            NSData *data=[NSData dataWithContentsOfURL:url];
            dispatch_async(dispatch_get_main_queue(),^{
                UIImage *img=[UIImage imageWithData:data];
                self.rightImageView.image=img;
            });
        });

    
        
        
//        NSURL *url=[NSURL URLWithString:model.flag];
//        NSData *data=[NSData dataWithContentsOfURL:url];
//        
//        UIImage *img=[UIImage imageWithData:data];
//        self.rightImageView.image=img;
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.categoryNameLabel.textColor=UPColor(169, 169, 169);
}


//1.让cell的selection为none
/**
 *  2.设置线为hidden
 *
 *  3.选中哪个cell就让该cell中左边的线显示出来
        self.leftLine.hidden=!selected;
 *
 */
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    //选中哪个cell就让该cell中左边的线显示出来
    self.leftLine.hidden=!selected;
    
    if (selected) {
        //选中状态下背景颜色及字体颜色
        self.backgroundColor=[UIColor whiteColor];
        self.categoryNameLabel.textColor=[UIColor blackColor];
    }else
    {
        //非选中状态下背景颜色及字体颜色
        self.backgroundColor=[UIColor clearColor];
        self.categoryNameLabel.textColor=UPColor(169, 169, 169);
    }
    
}

@end
